var findKthLargest = function (nums, k) {
  // 数组排序
        // 快排
  function sort(currArray) {
    const pivot = currArray[0];
    let left = 0;
    let right = currArray.length - 1;
    let currDirection = "right";
    for (let i = 0; i < currArray.length; i++) {
      if (left === right) {
        currArray[right] = pivot;
        break;
      }
      if (currDirection === "right") {
        if (currArray[right] > pivot) {
          right--;
        } else {
          currArray[left] = currArray[right];
          left++;
          currDirection = "left";
        }
      } else {
        if (currArray[left] > pivot) {
          currArray[right] = currArray[left];
          right--;
          currDirection = "right";
        } else {
          left++;
        }
      }
    }
    const leftArr = currArray.slice(0, left);
    if (leftArr.length > 1) {
      sort(leftArr); //这个调用把左子序列排序好
    }
    const rightArr = currArray.slice(left + 1);
    if (rightArr.length > 1) {
      sort(rightArr); //这个调用把右子序列排序好
    }

    return [...leftArr, pivot, ...rightArr];
  }
const sortArr =sort(nums);
  // 在排序后的数组里面取第k大元素
  return sortArr[sortArr.length - k]
};
const a = findKthLargest([3, 5, 6, 1, 2, 4],2);
console.log(a);
